<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class StdInsertController extends Controller
{
    /*
    展示表单的
     */
    public function insertform()
    {
        return view('std_create');
    }

    /*
    保存到数据库
     */
    public function insert(Request $request)
    {
        $name = $request->input("std_name");
        Db::insert('insert into student (name) value (?)', [$name]);
        echo "Record inserted successfully.<br/>";
        echo '<a href="/insert">click here</a> to go back.';
    }
    /**
    更新数据
    */
    public function update()
    {
        $id = 1;
        $name = "updated";
        Db::update('update student set name = ? WHERE id = ?', [$name, $id]);
        echo "ok";
    }

    /*
    删除数据
    */
    public function destroy($id)
    {
        DB::delete('delete from student where id = ?', [$id]);
        echo "Record deleted successfully.<br/>";
        echo '<a href="/delete-records">Click Here</a> to go back.';
    }
}
